/* $RCSFile: DebugError.aspx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/app_support/DebugError.aspx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:18  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:43:41  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:24  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AddonNice.Configuration;

namespace AddonNice.Error
{
    /// <summary>
    /// Default Error page
    /// </summary>
    public partial class DebugError : System.Web.UI.Page
    {


        #region Web Form Designer generated code
        /// <summary>
        /// Raises the Init event.
        /// </summary>
        /// <param name="e"></param>
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new EventHandler(this.Page_Load);

        }
        #endregion

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (HttpContext.Current == null)
                return;
            Exception ex = HttpContext.Current.Server.GetLastError();
            if (Request.Params["code"] != null)
            {
                ErrorLit.Text = string.Format("code={0}", Request.Params["code"]);
            }

            if (ex == null)
                return;
            StringBuilder sb = new StringBuilder();

            HttpContext context = HttpContext.Current;
            while (ex != null)
            {
                sb.Append("Type: " + ex.GetType().FullName + Environment.NewLine);// RC4
                sb.Append("Message: " + ex.Message + Environment.NewLine);
                sb.Append("Source: " + ex.Source + Environment.NewLine);
                sb.Append("TargetSite: " + ex.TargetSite + Environment.NewLine);
                sb.Append("StackTrace: " + ex.StackTrace + Environment.NewLine);
                sb.Append(Environment.NewLine + Environment.NewLine);
                ex = ex.InnerException;
            }
            sb.Append(Environment.NewLine);


            ErrorLit.Text = ErrorLit.Text + sb.ToString();

        }
    }
}